import {Modal} from 'antd';
import isFunction from 'lodash/isFunction';
import {WeaLocaleProvider} from 'ecCom';
import {createReplyBottomAtt } from '../../util/communicationUtil';

const getLabel = WeaLocaleProvider.getLabel;


class ReplyItem extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const {approvalAtatus, discussantInfo = {},remark , showDate, commentuserInfo, id, createDate, createTime, createUserName, 
    createUser, resiveUser, resiveUserName, canModify, hasSubmitRight=false, createUserType = '1', resiveUserType = '1' } = this.props;
    const {isAnonymous, isDel} = this.props;
    const {op_isComCanDelete, op_isComCanReply} = this.props;
    const {
      relatedaccList4E9 = [], 
      relatedcusList4E9 = [], 
      relateddocList4E9 = [], 
      relatedprjList4E9 = [], 
      relatedwfList4E9 = [], 
      relatemutilprjs4E9 = []
    } = this.props;
    return (
      <div className="wea-cowork-comment-item">
        <div>
          <div>
            <div className="cowork-reply-content">
              <div>
                  <span className="cowork-reply-user">
                    {isAnonymous == 1 ? <span >{discussantInfo.lastname}</span>:
                      <React.Fragment>
                      { createUserType == '1' && <a  href={`javaScript:openhrm(${createUser});`} onClick={window.pointerXY}>{createUserName}</a> }
                      { createUserType == '2' &&  <a href={`javaScript: window.open('/spa/crm/static/index.html#/main/crm/customerView?customerId=${createUser}&_key=jfzmyh', '_blank')`}>{createUserName}</a>}
                    </React.Fragment>
                    }
                    {resiveUser > -1  && (
                      <span>
                        <span className="ml5">{getLabel(128123, '回复')}</span>
                        {resiveUserType == '1' && <a className="ml5" href={`javaScript:openhrm(${resiveUser});`} onClick={window.pointerXY} >{resiveUserName}</a>}
                        {resiveUserType == '2' && <a className="ml5" href={`javaScript: window.open('/spa/crm/static/index.html#/main/crm/customerView?customerId=${resiveUser}&_key=jfzmyh', '_blank')`} >{resiveUserName}</a>}
                      </span>
                    )}
                    <span className="reply-time">{showDate}</span>
                  </span>
                <span className="fr">
                  {canModify && hasSubmitRight && <span className="cowork-top-icon icon-coms-delete" onClick={this.delete} title={getLabel(91,'删除')}/>}
                  { hasSubmitRight && <span className="cowork-top-icon icon-coms-New-SMS" onClick={this.props.reply.bind(this, id, createUser,createUserName, createUserType)} title={getLabel(128123, '回复')}/>}
                </span>
              </div>
              <div className="cowork-reply-remark wea-f12">
                <div
                  className="wea-cl-content"
                  dangerouslySetInnerHTML={{__html: `<div class="wea-ckeditor-content">${remark}</div>`}}
                />
              </div>
              <div className="workflow-resource-list">
                {createReplyBottomAtt(getLabel(857, '相关文档')+':', relateddocList4E9, ()=>{}, "doc")}
                {createReplyBottomAtt(getLabel(1044, '相关流程') + ':',relatedwfList4E9, ()=>{}, "wf")}
                {createReplyBottomAtt(getLabel(783, '相关客户') + ':',relatedcusList4E9, ()=>{}, "crm")}
                {createReplyBottomAtt(getLabel(782, '相关项目') + ':',relatemutilprjs4E9, ()=>{}, "project")}
                {createReplyBottomAtt(getLabel(33414, '相关任务')+':',relatedprjList4E9, ()=>{}, "task")}
                {createReplyBottomAtt(getLabel(33414, '相关附件')+':',relatedaccList4E9, ()=>{}, "acc")}
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
  
  delete = () => {
    let that = this;
    const { changePageNum } = this.props;
    Modal.confirm({
      content: getLabel(512301, '确认要删除该评论吗？'),
      onOk() {
        changePageNum();
        isFunction(that.props.operate) && that.props.operate({
          id: that.props.id,
          operationType: 'delReply'
        });
      }
    });
  }
}

export default ReplyItem;